/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

import Utils.DBConnection;
import Utils.Settings;
import Utils.Utils;
import com.mysql.jdbc.Util;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author user
 */
public class CategoryModel {

    DBConnection db = new DBConnection(Settings.getDb(), Settings.getDbLogin(), Settings.getDbPassword());
    String message;

    public HashMap GetCategory(int categoryID) {
        try {
            String querry = "SELECT * FROM categories WHERE CategoryID=" + categoryID;

            ResultSet rs = db.ExecuteQuery(querry);
            ArrayList Rows = Utils.resultSetToArrayList(rs);
            return (HashMap)Rows.get(0);
        } catch (Exception ex) {
            return null;
        } finally {
            //  db.close();
        }
    }

    public ArrayList GetMasterCategories() {
        try {
            String querry = "SELECT * FROM categories	WHERE CategoryMasterID IS NULL";

            ResultSet rs = db.ExecuteQuery(querry);
            ArrayList Rows = Utils.resultSetToArrayList(rs);
            return Rows;
        } catch (Exception ex) {
            return null;
        } finally {
            //  db.close();
        }
    }

    public ArrayList GetSubCategories(int categoryID) {
        try {
            String querry = "SELECT * FROM categories WHERE (CategoryMasterID = " + categoryID + ") || " + categoryID + "=-1";

            ResultSet rs = db.ExecuteQuery(querry);
            ArrayList Rows = Utils.resultSetToArrayList(rs);
            return Rows;
        } catch (Exception ex) {
            return null;
        } finally {
            //  db.close();
        }
    }
}
